import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.net.Socket;
import java.util.Random;


public class Game implements PropertyChangeListener
{
	protected PropertyChangeSupport pCS;
	private SocketServer server;
	private Player[] players;
	private Deck deck ;
	private int startCoins;
	private int whoDealer;
	private int whoseTurn;
	private int stake; // aktualna stawka
	private int round;
	int i=0;
	
	public Game(int playersNr, int startCoins, int port, String name, PlayFrame openFrame )
	{
		this.players = new Player[7];
		this.startCoins = startCoins;
		this.server = new SocketServer(port,this);
		openFrame.dispose();
		server.start();
		
		this.deck = new Deck();
		whoDealer = drawDealer(playersNr);
		
	}
	public void sitPlayer(String name, Socket client)
	{
		i++;
		players[i] = new Player(name, i, client, server, startCoins, deck);
		//dodanie nowych graczy do okienek już istniejących 
		for(int j=1; j<i; j++)
		{
			players[j].addNewPlayer(name);
		}
		System.out.println("Jestem w sitPlayer");
		Thread t = new Thread( players[i]);
		System.out.println("Utworzony");
		t.start();
	}
	public int drawDealer(int players){
		Random random = new Random();
		return (random.nextInt(players)+1);
	}
	@Override
	public void propertyChange(PropertyChangeEvent arg0)
	{
		// TODO Auto-generated method stub
		
	}
}
